package ev.selection;//need to add this line

import java.util.*;

import TeamPursuit.SimulationResult;
import TeamPursuit.WomensTeamPursuit;

import ev.initial.Individual;

public class SimpleSelection implements Selection{

	public ArrayList<Individual> select(ArrayList<Individual> oldPopulation, int limit)
	{
		Random r=new Random();
		int size=oldPopulation.size();
		if(size<limit){
			//System.exit(0);
			System.out.println("error: limit can not be larger than population size");
		}
		Collections.sort(oldPopulation);
		ArrayList<Individual> newPopulation=new ArrayList<Individual>();
		for(int i=0; i<3; i++){
			newPopulation.add(oldPopulation.get(i));
		}
		for(int i=3; i<limit; i++){
			newPopulation.add(oldPopulation.get(r.nextInt(size-3)+3));
		}
		
		return newPopulation;
	}
	private boolean isValid(SimulationResult result){
		if(result.getProportionCompleted() < 0.9999998){
			return false;
		}else{
			return true;
		}
	}
}
